<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Str;

class Component extends Model
{

    protected $casts = [
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
        'tags' => 'array',
        'industry' => 'array',
        'included' => 'array',
        'related' => 'array',
        'categories' => 'array',
        'viewports' => 'array',
    ];
    public function ComponentTypes():hasMany
    {
        return $this->hasMany(ComponentType::class);
    }

    public function categories():BelongsToMany
    {
        return $this->belongsToMany(ComponentCategory::class, 'component_component_category');
    }

    public function setDescriptionAttribute($value)
    {
        $this->attributes['description_html'] = Str::markdown($value);
    }
}
